package harima.agameditor.common.control;

import java.io.File;
import java.util.HashMap;

public class AwesomeEditorEnviroment {
	
	static HashMap<String, String> paths;
	static Project currentProject;
	
	public static final String ROOT_PATH = "ROOT_PATH";
	public static final String MAPS_PATH = "MAPS PATH";
	
	public static String pathSeparator = System.getProperty("file.separator");
	
	private static HashMap<String, String> getPaths()
	{
		if(paths == null){paths = new HashMap<String, String>(); putPaths();}	
		return paths;
	}	

	public static String getPath(String name){
		String path =getPaths().get(name);		
		if(path != null && name != ROOT_PATH)
		{
			path = getPath(ROOT_PATH) + pathSeparator + path;
		}		
		return path;
	}

	public static boolean createProject(Project project) {
		boolean created = new ProjectUtils().createProjectDirectories(project.getRootPath());
		currentProject = project;
		setRootPath(project.getRootPath());
		if(!created){clearEnvyroment();}
		return created;
	}

	private static void putPaths() {paths.put(MAPS_PATH, "maps");}
	public static Project getCurrentProject() {return currentProject;	}
	public static void setRootPath(String path) {getPaths().put(ROOT_PATH, path);}

	public static boolean deleteCurrentProject() {
		boolean deleted = false;
		
		if(currentProject != null)
		{
			deleted = new ProjectUtils().deleteDirectory(currentProject.getRootPath());
			clearEnvyroment();			
		}
		else{ deleted = true;}
		return deleted;
	}

	public static void clearEnvyroment() {
		currentProject  = null;
		paths= null;
	}
}
